package com.yihuier.yihuier.Mapper.UserManager;

import com.yihuier.yihuier.Entity.UserManager.Manager;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ManagerMapper {

    @Select("SELECT manager_id from bz_manager where manager_belongs_company = #{company_id};")
    int[] selectManagerIdsByCompanyId(@Param("company_id") int company_id);

    @Select("SELECT manager_belongs_company from bz_manager where manager_id = #{manager_id};")
    int selectCompanyIdByManagerId(@Param("manager_id") String manager_id);

    @Select("SELECT manager_id from bz_manager where manager_account = #{manager_account} AND manager_password = #{user_password};")
    String selectManagerIdByAccountAndPassword(@Param("manager_account") String manager_account,@Param("user_password") String user_password);

    @Select("SELECT manager_belongs_company from bz_manager where manager_id = #{manager_id};")
    String judgeSuperManager(@Param("manager_id") String manager_id);

    @Select("SELECT manager_id from bz_manager where manager_belongs_company = #{company_id} AND manager_type = 1 LIMIT 1")
    int selectAIManager(@Param("company_id") int company_id);

    @Select("SELECT manager_username from bz_manager where manager_id = #{manager_id} AND manager_status = 1 LIMIT 1")
    String selectManagerNameByManagerId(@Param("manager_id") String manager_id);

    @Insert("INSERT into bz_manager(manager_account,manager_username,manager_password,manager_role,manager_belongs_company,manager_type) VALUES(#{manager_account},#{manager_username},#{manager_password},2,#{manager_belongs_company},#{manager_type})")
    int insertManager(@Param("manager_account") String manager_account,@Param("manager_username") String manager_username,@Param("manager_password") String manager_password,@Param("manager_belongs_company") int manager_belongs_company,@Param("manager_type") String manager_type);

    @Select("SELECT  Count(manager_id) FROM `bz_manager` WHERE manager_belongs_company = #{company_id};")
    int selectSumOfManagersInCompany(@Param("company_id") int company_id);

    @Results({
        @Result(property = "manager_id" , column = "manager_id"),
        @Result(property = "manager_account" , column = "manager_account"),
        @Result(property = "manager_username" , column = "manager_username"),
        @Result(property = "manager_belongs_company" , column = "manager_belongs_company"),
        @Result(property = "manager_status" , column = "manager_status"),
        @Result(property = "manager_type" , column = "manager_type"),
    })
    @Select("SELECT manager_id, manager_account,manager_username,manager_belongs_company,manager_status,manager_type from bz_manager WHERE manager_status = 1 AND manager_belongs_company != 1 order by manager_belongs_company")
    List<Manager> selectManagersForSuperManager();

    @Update("UPDATE bz_manager SET manager_status = #{manager_status} WHERE manager_id = #{manager_id}")
    int setManagerStatus(@Param("manager_id") int manager_id,@Param("manager_status") int manager_status);

}
